home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 3 / Amethyst.iso / rl / build-bin / fup < prev    next >
Encoding:
Text File  |  2002-06-03  |  3.4 KB  |  147 lines

  1. #!/bin/sh
  2. # fup - file update script
  3. # copyright (c) 2000, joseph cheek, joseph@redmondlinux.org
  4. # released under gpl.
  5. # $1: full pathname of updated file
  6. # $2: directory [inside buildroot] to place file
  7. # ex: fup /home/joseph/myfile col/devel
  8. # opts: -q: quiet [don't print status messages]
  9. #       -f: force [update even when older]
  10. #       -l: language to add to [default: all languages]
  11.  
  12. # BUG: use getopts instead
  13. LANG=
  14.  
  15. if [ "n$1" = "n-q" ]; then # -q
  16.   QUIET="-q"
  17.   shift
  18. fi
  19.  
  20. if [ "n$1" = "n-f" ]; then # -f
  21.   FORCE="(force)"
  22.   shift
  23. fi
  24.  
  25. if [ "n$1" = "n-l" ]; then # -l
  26.   LANG="$2"
  27.   shift
  28.   shift
  29. fi
  30.  
  31. if [ ! -r "$1" ]; then # file doesn't exist
  32. ( echo `basename $0`: can\'t find \"$1\"
  33.   echo
  34.   echo usage: `basename $0` \[-q\] \[-f\] \[-l lang\] file dir
  35.   echo updates file in dir of redmond linux build system
  36.   echo -q is quiet, ie don\'t print status messages
  37.   echo -f is force, ie update even if updated file is older
  38.   echo -l is language or all if not present ) >&2
  39.   exit 1
  40. fi
  41.  
  42. if [ $# -lt 2 ]; then # no dir given
  43. ( echo `basename $0`: no dir given
  44.   echo perhaps you wanted pup?
  45.   echo
  46.   echo usage: `basename $0` \[-q\] \[-f\] \[-l lang\] file dir
  47.   echo updates file in dir of redmond linux build system
  48.   echo -q is quiet, ie don\'t print status messages
  49.   echo -f is force, ie update even if updated file is older
  50.   echo -l is language or all if not present ) >&2
  51.   exit 1
  52. fi
  53.  
  54. # constants and vars
  55.  
  56. RL_ROOT=/opt/redmondlinux
  57. BUILD_NUM_FILE=$RL_ROOT/builds/CURRENT_BUILD
  58. BUILD_NUM=`cat $BUILD_NUM_FILE`
  59. BUILD_ROOT=$RL_ROOT/builds/$BUILD_NUM
  60.  
  61. BASENAME=`basename "$1"`
  62.  
  63. cd $BUILD_ROOT
  64. LANG_TO_PROCESS=`echo ${LANG}*`
  65. cd -
  66.  
  67. for lang in $LANG_TO_PROCESS; do
  68.  
  69.   CHANGELOG=$BUILD_ROOT/$lang/CHANGELOG
  70.   UPDATED_FILE="$BUILD_ROOT/$lang/$2/$BASENAME"
  71.  
  72.  
  73. # more error checks
  74.  
  75.   if [ ! -d $BUILD_ROOT/$lang/"$2" ]; then # dir doesn't exist
  76.   ( echo `basename $0`: can\'t find \"$BUILD_ROOT/$lang/$2\"
  77.     echo
  78.     echo usage: `basename $0` \[-q\] \[-f\] \[-l lang\] file dir
  79.     echo updates file in dir of redmond linux build system
  80.     echo -q is quiet, ie don\'t print status messages
  81.     echo -f is force, ie update even if updated file is older
  82.     echo -l is language or all if not present ) >&2
  83.     exit 1
  84.   fi
  85.  
  86.   if [ ! -f "$UPDATED_FILE" ]; then # updated file doesn't exist
  87.   ( echo `basename $0`: can\'t find \"$UPDATED_FILE\"
  88.     echo perhaps you need to add it, not update it ) >&2
  89.     exit 1
  90.   fi
  91.  
  92.   if [ ! "$1" -nt "$UPDATED_FILE" -a -z "$FORCE" ]; then # timestamps say it's not newer
  93.   ( echo `basename $0`: "$1" isn\'t newer than $UPDATED_FILE
  94.     echo use -f to force updating ) >&2
  95.     exit 1
  96.   fi
  97.  
  98. #
  99. #
  100. # get data of file to be replaced
  101.  
  102. # uid, gid
  103.  
  104.   _UID=`ls -l "$UPDATED_FILE" | tr -s \  | cut -d \  -f 3`
  105.   _GID=`ls -l "$UPDATED_FILE" | tr -s \  | cut -d \  -f 4`
  106.  
  107.  
  108. # perform the update
  109.  
  110. # copy the file
  111.  
  112.   cp -f "$1" "$UPDATED_FILE"
  113.   if [ "$?" -gt 0 ]; then # file copy failed
  114.   ( echo `basename $0`: copy failed
  115.     echo perhaps you need to add it, not update it ) >&2
  116.     exit 1
  117.   fi
  118.  
  119. # chown
  120.  
  121.   chown $_UID.$_GID "$UPDATED_FILE"
  122.   if [ "$?" -gt 0 ]; then # chown failed
  123.   ( echo `basename $0`: chown failed
  124.     echo not a fatal error, but check ownership of "$UPDATED_FILE" ) >&2
  125.   fi
  126.  
  127. # update changelog
  128.  
  129.   echo u "$2/$BASENAME" "$FORCE" >> $CHANGELOG
  130.  
  131.   if [ "$?" -gt 0 ]; then # update changelog failed
  132.   ( echo `basename $0`: update changelog failed
  133.     echo check permissions on $CHANGELOG ) >&2
  134.     exit 1
  135.   fi 
  136.  
  137.  
  138.   tail -n 1 $CHANGELOG
  139.  
  140. done
  141.  
  142. exit 0
  143.